package pcjavanet.mobilesell.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import pcjavanet.mobilesell.model.Area;
import pcjavanet.mobilesell.model.Employee;
import pcjavanet.mobilesell.model.PageBean;
import pcjavanet.mobilesell.model.QryCondition;
import pcjavanet.mobilesell.service.AreaService;
import pcjavanet.util.LogUtil;

import com.opensymphony.xwork2.ActionSupport;
@Namespace("/area")
@Controller
@Scope("prototype")
@ParentPackage("json-default")
@Results({
	@Result(name = "success", location = "/view/Area.jsp"),
	@Result(name = "input", location = "/view/Area.jsp")
})

public class AreaAction  extends ActionSupport {
  @Resource
  private AreaService areaService;
  private   java.lang.Integer dbid ;
  private   java.lang.String name ;
  private   java.util.Date createDate ;
  private int start  ;
  private int limit  ;
  private int totalProperty  ;
  private boolean success = true ;
  private String  info ;
  private List<Area>  areaPageBeans  ;
  public    java.lang.Integer getDbid() {
   	return this.dbid;
  }
  public void setDbid(  java.lang.Integer  dbid) {
   	 this.dbid=dbid;
  }
  public    java.lang.String getName() {
   	return this.name;
  }
  public void setName(  java.lang.String  name) {
   	 this.name=name;
  }
  public    java.util.Date getCreateDate() {
   	return this.createDate;
  }
  public void setCreateDate(  java.util.Date  createDate) {
   	 this.createDate=createDate;
  }
  public  void setStart(int start) {
   	 this.start = start;
  }
  public  void setLimit(int limit) {
   	 this.limit = limit;
  }
  public  void setTotalProperty(int totalProperty) {
   	 this.totalProperty = totalProperty;
  }
  public  void setAreaPageBeans(List<Area> areaPageBeans){
   	 this.areaPageBeans =areaPageBeans  ;
  }
  public  int getStart( ) {
   	 return this.start;
  }
  public  int getLimit( ) {
   	 return this.limit;
  }
  public  int getTotalProperty( ) {
   	 return this.totalProperty;
  }
  public    List<Area> getAreaPageBeans(){
   	 return this.areaPageBeans   ;
  }
  public  String getInfo( ) {
   	 return this.info;
  }
  public  void setInfo(String info){
   	 this.info = info ;
  }
  public  boolean getSuccess( ) {
   	 return this.success;
  }
  public  void setSuccess(boolean success){
   	 this.success = success ;
  }

  @Action(value="insertArea",results = {@Result(name = "success", type = "json")})
  public String  insertArea() throws Exception{
   	success = false ;
   	info = "" ;
  	Area bean = new Area();
  	bean.setName(this.name); 
  	bean.setCreateDate(this.createDate); 
	areaService.insert(bean);
	javax.servlet.http.HttpServletRequest request =(javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST);
	Object empolyeeBean =  request.getSession().getAttribute("employee") ;
	 if (  empolyeeBean != null ) {
		int refEmployeeDbid = ( ( Employee ) empolyeeBean).getDbid();
		 LogUtil.addLog(refEmployeeDbid, LogUtil.OPERATOR_KEY_INSERT , Area.MODULE_ID );
	 }
   	success = true ;
   	info = "Add Successful" ;
   	return SUCCESS;
  }

  @Action(value="queryArea",results = {@Result(name = "success", type = "json")})
  public String  queryArea() throws Exception{
  	Area bean = new Area();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setCreateDate(this.createDate); 
	areaService.selectByPrimaryKey(bean);
   	return SUCCESS;
  }

  @Action(value="updateArea",results = {@Result(name = "success", type = "json")})
  public String  updateArea() throws Exception{
   	success = false ;
   	info = "" ;
  	Area bean = new Area();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setCreateDate(this.createDate); 
  	bean =areaService.selectByPrimaryKey(bean);
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setCreateDate(this.createDate); 
	areaService.updateByPrimaryKeySelective(bean);
	javax.servlet.http.HttpServletRequest request =(javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST);
	Object empolyeeBean =  request.getSession().getAttribute("employee") ;
	 if (  empolyeeBean != null ) {
		int refEmployeeDbid = ( ( Employee ) empolyeeBean).getDbid();
		 LogUtil.addLog(refEmployeeDbid, LogUtil.OPERATOR_KEY_VIEW ,Area.MODULE_ID);
	 }
   	success = true ;
   	info = "Update Successful" ;
   	return SUCCESS;
  }

  @Action(value="deleteArea",results = {@Result(name = "success", type = "json")})
  public String  deleteArea() throws Exception{
  	Area bean = new Area();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setCreateDate(this.createDate); 
	areaService.deleteByPrimaryKey(bean);
	javax.servlet.http.HttpServletRequest request =(javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST);
	Object empolyeeBean =  request.getSession().getAttribute("employee") ;
	 if (  empolyeeBean != null ) {
		int refEmployeeDbid = ( ( Employee ) empolyeeBean).getDbid();
		 LogUtil.addLog(refEmployeeDbid, LogUtil.OPERATOR_KEY_DELETE ,Area.MODULE_ID );
	 }
   	return SUCCESS;
  }

  @Action(value="listArea",results = {@Result(name = "success", type = "json")})
  public String  listArea() throws Exception{
 	QryCondition qry = RequestUtil.getQryCondition(   (javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST)); 	PageBean pageBean = new PageBean();
	pageBean.setPageSize( limit );
	pageBean.setStartCount( start );
	totalProperty =areaService.getTotalRecords( qry, pageBean );
	areaPageBeans =areaService.getOnePageBeans( qry, pageBean );
   	return SUCCESS;
  }

  @Action("index")
  public String index() throws Exception{
   	return SUCCESS;
  }

}
